<template>
	<view>
		<image @tap="goLive()" class="banner" src="../../static/banner/liveBanner.png" mode=""></image>
		<view v-if="data != '' " class="content">
			<li v-if="v.live_status == 101 || live_status == 102 " @tap="open(v)" v-for="(v,i) in data" :key="i">
				<image class="cover" :src="v.share_img" mode=""></image>
				<view class="txt">
					<p class="title one">
						{{v.name}}
					</p>
					<p class="user ">
						{{v.anchor_name}}
					</p>
					<p class="btn">立即观看</p>
				</view>
				<view class="tag">
					<image class="vm" src="../../static/image/live.png" mode=""></image>
					{{v.types}}
				</view>
			</li>
		</view>
		<view v-if="data =='' " class="dataNone">
			<image src="../../static/image/noneLive.png" mode=""></image>
			<p>暂无直播内容呦~</p>
		</view> 
	</view>
</template>

<script>
	import {
		getAccessToken
	} from '../../api/api.js'
	export default {
		data() {
			return {
				AccessToken: '',
				data: [],
				start: 0,
				stops: 0,
				limit: 10
			};
		},
		onLoad() {
			// this.init() 
		},
		onReachBottom() {
			if (this.stops == 0) {
				this.liveList()
			}
		},
		methods: {
			goLive(){
				this.$navigateTo('../livePlay/livePlay')
			},
			open(v) {
				let roomId = v.roomid
				let customParams = 'test'
				wx.navigateTo({
					url: `plugin-private://wx2b03c6e691cd7370/pages/live-player-plugin?room_id=${roomId}&custom_params=${customParams}`
				})
			},
			async init() {
				uni.request({
					url: 'https://mall.h5.eper.cctv8.co/eper-mall/api/socialUser/getAccessToken',
					method: 'POST',
					success: (res) => {
						this.AccessToken = res.data.data
						uni.setStorageSync('AccessToken', this.AccessToken)
						if (res.data.code == 0) {
							this.liveList()
						}
					}
				})
			},
			liveList() {
				uni.request({
					url: 'https://api.weixin.qq.com/wxa/business/getliveinfo?access_token=' + this.AccessToken,
					method: 'POST',
					data: {
						"start": this.start,
						"limit": this.limit
					},
					success: (res) => {
						let data = res.data.room_info
						if (this.limit == data.length) {
							this.start = this.start + this.limit
						} else {
							this.stops = 1
						}
						let arrLive = []
						for (let i = 0; i < data.length; i++) {
							if (data[i].live_status == 101) {
								data[i].types = '直播中'
								arrLive.push(data[i])
								
							}
							if (data[i].live_status == 102) {
								data[i].types = '未开始'
								arrLive.push(data[i])
							}
							if (data[i].live_status == 103) {
								data[i].types = '已结束'
							}
							if (data[i].live_status == 104) {
								data[i].types = '禁播'
							}
							if (data[i].live_status == 105) {
								data[i].types = '暂停'
							}
							if (data[i].live_status == 106) {
								data[i].types = '异常'
							}
							if (data[i].live_status == 107) {
								data[i].types = '已过期'
							}
						}
						this.data = [...this.data, ...arrLive]
					}
				})
			}
		}
	}
</script>

<style lang="less" scoped>
	@import './index.less';
</style>
